package coms.delegates;

import EJB.EJBLocator;
import coms.dto.Publication;
import coms.dto.User;
import coms.ejb.PublicationBeanRemote;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

public class PublicationDelegate implements IDelegate<Publication> {

    private PublicationBeanRemote publicationBean;
    
    public PublicationDelegate() {
        try {
            this.publicationBean = EJBLocator.lookupPublicationBean();
        } catch (Exception ex) {
            Logger.getLogger(PublicationDelegate.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    @Override
    public boolean create(Publication publication) {
        publicationBean.create(publication);
        return true;
    }

     @Override
    public boolean delete(Publication publication) {
        boolean deleted = publicationBean.delete(publication);
        return deleted;
    }

     @Override
    public boolean update(Publication publication) {
        publicationBean.update(publication);
        return true;
    }

    @Override
    public List<Publication> search(Publication publication) throws Exception {
        return publicationBean.search(publication);
    }

    @Override
    public List<Publication> findAll() throws Exception {
        return publicationBean.findAll();
    }

    @Override
    public Publication getById(int id) throws Exception {
       return publicationBean.getById(id);
    }
    

    public List<Publication> getByAnyAuthorType(User author) throws Exception {
    return publicationBean.getByAnyAuthorType(author);
    
    }
    
}
